<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>在线简历生成器</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/html2pdf.js@0.9.3/dist/html2pdf.bundle.min.js"></script>
  <style>
    body {
      background-color: #ecf0f1; /* 浅灰色背景 */
      color: #2c3e50;
      font-family: 'Arial', sans-serif;
      margin: 0;
      padding: 0;
    }

    .container {
      margin-top: 50px;
      margin-bottom: 50px;
      max-width: 1000px;
    }

    .card {
      border: none;
      border-radius: 12px;
      background-color: #ffffff; /* 填写信息区域背景为白色 */
      color: #2c3e50;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    }

    .card-header {
      font-size: 24px;
      font-weight: bold;
      background-color: #34495e;
      color: rgba(255, 255, 255, 0.97);
      border-radius: 12px 12px 0 0;
      text-align: center;
    }

    .form-label {
      font-weight: bold;
      color: #2c3e50;
    }

    .btn {
      border-radius: 8px;
      transition: all 0.3s ease-in-out;
    }

    .btn-primary {
      background: #1abc9c;
      border: none;
    }

    .btn-primary:hover {
      background: #16a085;
      transform: scale(1.05);
    }

    .btn-secondary {
      background: #7f8c8d;
      border: none;
    }

    .btn-secondary:hover {
      background: #95a5a6;
      transform: scale(1.05);
    }

    .btn-success {
      background: #27ae60;
      border: none;
    }

    .btn-success:hover {
      background: #2ecc71;
      transform: scale(1.05);
    }

    .resume-preview {
      background: #34495e;
      color: #ecf0f1;
      padding: 20px;
      border-radius: 12px;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
      margin-top: 30px;
    }

    .resume-preview h1, .resume-preview h2 {
      color: #1abc9c;
    }

    .resume-preview p, .resume-preview ul {
      margin: 0 0 10px;
    }

    .resume-preview ul {
      list-style-type: none;
      padding: 0;
    }

    .resume-preview ul li::before {
      content: '•';
      color: #1abc9c;
      font-weight: bold;
      display: inline-block;
      width: 1em;
    }

    .footer {
      background-color: #2c3e50;
      color: #ecf0f1;
      text-align: center;
      padding: 10px 0;
      font-size: 14px;
    }

  </style>
</head>
<body>

<div class="container">
  <h1 class="text-center mb-4" style="font-weight: bold; font-size: 36px;">在线简历生成器</h1>
  <p class="text-center text-light mb-5" style="font-size: 18px;">轻松填写信息，即可生成个性化简历</p>

  <!-- 输入表单 -->
  <div class="card mb-4">
    <div class="card-header">填写信息</div>
    <div class="card-body">
      <form id="resumeForm">
        <div class="mb-3">
          <label for="name" class="form-label">姓名</label>
          <input type="text" id="name" class="form-control" placeholder="请输入您的姓名" required>
        </div>
        <div class="mb-3">
          <label for="email" class="form-label">邮箱</label>
          <input type="email" id="email" class="form-control" placeholder="请输入您的邮箱" required>
        </div>
        <div class="mb-3">
          <label for="phone" class="form-label">电话</label>
          <input type="text" id="phone" class="form-control" placeholder="请输入您的电话号码" required>
        </div>
        <div class="mb-3">
          <label for="address" class="form-label">地址</label>
          <input type="text" id="address" class="form-control" placeholder="请输入您的地址">
        </div>
        <div class="mb-3">
          <label for="education" class="form-label">教育背景</label>
          <textarea id="education" class="form-control" rows="3" placeholder="请输入您的教育背景"></textarea>
        </div>
        <div class="mb-3">
          <label for="projects" class="form-label">项目经历</label>
          <textarea id="projects" class="form-control" rows="3" placeholder="请输入您的项目经历"></textarea>
        </div>
        <div class="mb-3">
          <label for="skills" class="form-label">专业技能</label>
          <textarea id="skills" class="form-control" rows="3" placeholder="请输入您的专业技能"></textarea>
        </div>
        <div class="btn-group w-100">
          <button type="button" class="btn btn-primary" onclick="generateResume()">生成简历</button>
          <button type="button" class="btn btn-secondary" onclick="saveData()">保存数据</button>
          <button type="button" class="btn btn-success" onclick="downloadPDF()">导出为 PDF</button>
        </div>
      </form>
    </div>
  </div>

  <!-- 简历预览 -->
  <div class="resume-preview" id="resumePreview">
    <h1 class="text-center">您的简历预览将在这里显示</h1>
    <p class="text-center text-muted">请填写左侧表单后点击“生成简历”按钮。</p>
  </div>
</div>

<script>
  // **生成简历**
  function generateResume() {
    const name = document.getElementById("name").value;
    const email = document.getElementById("email").value;
    const phone = document.getElementById("phone").value;
    const address = document.getElementById("address").value;
    const education = document.getElementById("education").value;
    const projects = document.getElementById("projects").value;
    const skills = document.getElementById("skills").value;

    const resumeHTML = `
      <h1>${name}</h1>
      <p><strong>邮箱：</strong> <a href="mailto:${email}">${email}</a></p>
      <p><strong>电话：</strong> ${phone}</p>
      <p><strong>地址：</strong> ${address}</p>

      <h2>教育背景</h2>
      <p>${education.replace(/\n/g, "<br>")}</p>

      <h2>项目经历</h2>
      <p>${projects.replace(/\n/g, "<br>")}</p>

      <h2>专业技能</h2>
      <ul>
        ${skills.split("\n").map(skill => `<li>${skill}</li>`).join("")}
      </ul>
    `;
    document.getElementById("resumePreview").innerHTML = resumeHTML;
  }

  // **保存数据到 LocalStorage**
  function saveData() {
    const formData = {
      name: document.getElementById("name").value,
      email: document.getElementById("email").value,
      phone: document.getElementById("phone").value,
      address: document.getElementById("address").value,
      education: document.getElementById("education").value,
      projects: document.getElementById("projects").value,
      skills: document.getElementById("skills").value
    };
    localStorage.setItem("resumeData", JSON.stringify(formData));
    alert("数据已保存！");
  }

  // **加载数据**
  window.onload = function () {
    const savedData = localStorage.getItem("resumeData");
    if (savedData) {
      const formData = JSON.parse(savedData);
      document.getElementById("name").value = formData.name;
      document.getElementById("email").value = formData.email;
      document.getElementById("phone").value = formData.phone;
      document.getElementById("address").value = formData.address;
      document.getElementById("education").value = formData.education;
      document.getElementById("projects").value = formData.projects;
      document.getElementById("skills").value = formData.skills;
    }
  };

  // **导出为 PDF**
  function downloadPDF() {
    const element = document.getElementById("resumePreview");
    const opt = {
      margin: 1,
      filename: 'resume.pdf',
      html2canvas: { scale: 2 },
      jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
    };
    html2pdf().set(opt).from(element).save();
  }
</script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
